<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>Grammar Classification Test</title>
    <script src="./evidence.js"></script>
    <script src="/assets/application.js"></script>
  </head>
  <body>
    
    <p>Test results are logged to the console.</p>
    
    <script src="./fixtures/example_grammars.js"></script>
    <script>
    (function(){
      
      function parse(spec) {
        
        return Grammar.parse(spec).grammar;
        
      }
      
      function classifications(grammar) {
        
        var classification = grammar.calculate("grammar.classification");
        var k, result;
        
        result = {};
        
        for (k in classification) {
          if (classification[k].member)
            result[k] = true;
        }
        
        return result;
        
      }
      
      function isSetEqual(a, b) {
        
        return Set.count(Set.intersection(a, b)) === Set.count(a);
        
      }
      
      Evidence.Assertions.assertSetEqual = function(expected, actual, message) {
        
        this._assertExpression(
          isSetEqual(expected, actual),
          message || 'Failed assertion.',
          'Expected %o, got %o.', expected, actual
        )
        
      }
      
      var SUPPORTED_CLASSIFICATIONS = {
        ll1: true, lr0: true, slr1: true,
        lr1: true, lr1: true, lalr1: true
      }
      
      Evidence.Assertions.assertExampleClassifications = function(expected, name) {
        
        var actual = Set.intersection(classifications(parse(EXAMPLE_GRAMMARS[name])), SUPPORTED_CLASSIFICATIONS);
        
        this.assertSetEqual(expected, actual, name);
        
      }

      Evidence("GrammarClassificationTest", {
        
        testAgreement: function(t) {
          
          t.assertExampleClassifications({ "lr0": true }, "ll0-lr0-0.cfg");
          t.assertExampleClassifications({ "lr0": true }, "ll0-lr0-1.cfg");
          t.assertExampleClassifications({ "lr0": true }, "ll0-lr0-2.cfg");
          
          t.assertExampleClassifications({ "ll1": true, "lr0": true }, "ll1-lr0-0.cfg");
          t.assertExampleClassifications({ "ll1": true, "lr0": true }, "ll1-lr0-1.cfg");
          t.assertExampleClassifications({ "ll1": true, "lr0": true }, "ll1-lr0-2.cfg");
          
          t.assertExampleClassifications({ "lr0": true }, "ll2-lr0-0.cfg");
          t.assertExampleClassifications({ "lr0": true }, "ll2-lr0-1.cfg");
          t.assertExampleClassifications({ "lr0": true }, "ll2-lr0-2.cfg");
          
          t.assertExampleClassifications({ "lr0": true }, "oth-lr0-0.cfg");
          t.assertExampleClassifications({ "lr0": true }, "oth-lr0-1.cfg");
          t.assertExampleClassifications({ "lr0": true }, "oth-lr0-2.cfg");
          t.assertExampleClassifications({ "lr0": true }, "oth-lr0-3.cfg");
          
          t.assertExampleClassifications({ "ll1": true, "slr1": true }, "ll1-slr1-0.cfg");
          t.assertExampleClassifications({ "ll1": true, "slr1": true }, "ll1-slr1-1.cfg");
          t.assertExampleClassifications({ "ll1": true, "slr1": true }, "ll1-slr1-2.cfg");
          
          t.assertExampleClassifications({ "slr1": true }, "ll2-slr1-0.cfg");
          t.assertExampleClassifications({ "slr1": true }, "ll2-slr1-1.cfg");
          t.assertExampleClassifications({ "slr1": true }, "ll2-slr1-2.cfg");
          
          t.assertExampleClassifications({ "slr1": true }, "oth-slr1-0.cfg");
          t.assertExampleClassifications({ "slr1": true }, "oth-slr1-1.cfg");
          t.assertExampleClassifications({ "slr1": true }, "oth-slr1-2.cfg");
          
          t.assertExampleClassifications({ "ll1": true, "lalr1": true }, "ll1-lalr1-0.cfg");
          t.assertExampleClassifications({ "ll1": true, "lalr1": true }, "ll1-lalr1-1.cfg");
          t.assertExampleClassifications({ "ll1": true, "lalr1": true }, "ll1-lalr1-2.cfg");
          
          t.assertExampleClassifications({ "lalr1": true }, "ll2-lalr1-0.cfg");
          t.assertExampleClassifications({ "lalr1": true }, "ll2-lalr1-1.cfg");
          t.assertExampleClassifications({ "lalr1": true }, "ll2-lalr1-2.cfg");
          
          t.assertExampleClassifications({ "lalr1": true }, "oth-lalr1-0.cfg");
          t.assertExampleClassifications({ "lalr1": true }, "oth-lalr1-1.cfg");
          t.assertExampleClassifications({ "lalr1": true }, "oth-lalr1-2.cfg");
          t.assertExampleClassifications({ "lalr1": true }, "oth-lalr1-3.cfg");
          
          t.assertExampleClassifications({ "ll1": true, "lr1": true }, "ll1-lr1-0.cfg");
          t.assertExampleClassifications({ "ll1": true, "lr1": true }, "ll1-lr1-1.cfg");
          t.assertExampleClassifications({ "ll1": true, "lr1": true }, "ll1-lr1-2.cfg");
          
          t.assertExampleClassifications({ "lr1": true }, "ll2-lr1-0.cfg");
          t.assertExampleClassifications({ "lr1": true }, "ll2-lr1-1.cfg");
          t.assertExampleClassifications({ "lr1": true }, "ll2-lr1-2.cfg");
          
          t.assertExampleClassifications({ "lr1": true }, "oth-lr1-0.cfg");
          t.assertExampleClassifications({ "lr1": true }, "oth-lr1-1.cfg");
          t.assertExampleClassifications({ "lr1": true }, "oth-lr1-2.cfg");
          
          t.assertExampleClassifications({ }, "ll2-lr2-0.cfg");
          t.assertExampleClassifications({ }, "ll2-lr2-1.cfg");
          t.assertExampleClassifications({ }, "ll2-lr2-2.cfg");
          t.assertExampleClassifications({ }, "ll2-lr2-3.cfg");
          t.assertExampleClassifications({ }, "ll2-lr2-4.cfg");
          
          t.assertExampleClassifications({ }, "oth-lr2-0.cfg");
          t.assertExampleClassifications({ }, "oth-lr2-1.cfg");
          t.assertExampleClassifications({ }, "oth-lr2-2.cfg");
          
          t.assertExampleClassifications({ }, "oth-oth-0.cfg");
          t.assertExampleClassifications({ }, "oth-oth-1.cfg");
          t.assertExampleClassifications({ }, "oth-oth-2.cfg");
          t.assertExampleClassifications({ }, "oth-oth-3.cfg");
          t.assertExampleClassifications({ }, "oth-oth-4.cfg");
          t.assertExampleClassifications({ }, "oth-oth-5.cfg");
          
        }
        
      });
      
    })();
    </script>
    
  </body>
</html>
